/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jjsoft.disco.gco.view;

import com.jjsoft.disco.gco.mdl.Ingreso;
import com.jjsoft.disco.gco.ngc.IngresoManager;
import com.jjsoft.disco.gco.util.CSelecciones;
import com.jjsoft.disco.gco.util.MiModelo;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Johnny
 */
public class VVerTarjetasSinPagar extends javax.swing.JFrame {

    /**
     * Creates new form VVerTarjetasSinPagar
     */
    IngresoManager im = new IngresoManager();
    MiModelo modelo = new MiModelo();
    List<Ingreso> listaIngresos= new ArrayList();
    JTextField texto;
    JButton boton;
    public VVerTarjetasSinPagar(JTextField texto, JButton boton) {
        initComponents();
        this.texto=texto;
        this.boton=boton;
         String[] identificadores = {"Codigo", "Cliente","Fecha", "Consumo","# Hombres","# Mujeres"};
        this.modelo.setColumnIdentifiers(identificadores);
        dtgTarjetas.setModel(modelo);
        this.dtgTarjetas.getColumn("Cliente").setPreferredWidth(200);
        listaIngresos=im.buscarIngresosSinCerrar();
        if(listaIngresos!=null && listaIngresos.size()>0)
            cargaDatos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel10 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dtgTarjetas = new javax.swing.JTable();
        cmdSeleccionar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(0, 51, 255));
        jLabel10.setText("Tarjetas sin registrar Pago");

        dtgTarjetas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        dtgTarjetas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(dtgTarjetas);

        cmdSeleccionar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        cmdSeleccionar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/check.png"))); // NOI18N
        cmdSeleccionar.setText("  Seleccionar");
        cmdSeleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdSeleccionarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(193, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cmdSeleccionar)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(182, 182, 182))))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 594, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addGap(217, 217, 217)
                .addComponent(cmdSeleccionar, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(46, 46, 46)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(64, Short.MAX_VALUE)))
        );

        setSize(new java.awt.Dimension(630, 339));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void cmdSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdSeleccionarActionPerformed
        // TODO add your handling code here:
        if (dtgTarjetas.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(null, "Primero seleccione una tarjeta", "Error", JOptionPane.ERROR_MESSAGE);
        } else {

            texto.setText(listaIngresos.get(dtgTarjetas.getSelectedRow()).getCodigo());
            boton.doClick();
            this.dispose();
        }
    }//GEN-LAST:event_cmdSeleccionarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VVerTarjetasSinPagar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VVerTarjetasSinPagar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VVerTarjetasSinPagar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VVerTarjetasSinPagar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VVerTarjetasSinPagar(null,null).setVisible(true);
            }
        });
    }
    public void cargaDatos()
    {
        for(int i=0;i<listaIngresos.size();i++)
        {
            String[] ingreso= {listaIngresos.get(i).getCodigo(),listaIngresos.get(i).getCedula().getNombres()+" "+listaIngresos.get(i).getCedula().getApellidos(),listaIngresos.get(i).getHoraEntrada().toLocaleString(),listaIngresos.get(i).getFactura().getTotal().toString(),String.valueOf(listaIngresos.get(i).getNumeroPersonasH().toString()),String.valueOf(listaIngresos.get(i).getNumeroPersonasM().toString())};
            modelo.addRow(ingreso);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdSeleccionar;
    private javax.swing.JTable dtgTarjetas;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
